<template>
  <div id="box">
    <img src="../../img/BAC44AD64B789D19F6A4F18060C_6B9E9B54_BCE17.png">
    <el-form id="input_box" ref="form" :model="form" label-width="80px" :rules="rules">
      <div id="input_box_name">用户登陆</div>
      <div id="input_box_content">

        <el-row type="flex" justify="center">
          <el-form-item label="账号">
            <el-tooltip class="item" effect="dark" content="学号" placement="bottom">
            <el-input v-model="form.numb"
                      placeholder="请输入内容"
                      onKeyUp="value=value.replace(/[^\w\.\/]/ig,'')"
                      @keyup.enter.native="handleSubmit()"
                      auto-complete="off"></el-input>
            </el-tooltip>
          </el-form-item>
        </el-row>

        <el-row type="flex" justify="center">
          <el-form-item label="账号">
            <el-tooltip class="item" effect="dark" content="初始密码为身份证后6位" placement="bottom">
            <el-input v-model="form.password"
                      placeholder="请输入密码"
                      show-password onKeyUp="value=value.replace(/[^\w\.\/]/ig,'')"
                      @keyup.enter.native="handleSubmit()"
                      auto-complete="off"></el-input>
            </el-tooltip>
          </el-form-item>
        </el-row>

        <el-row type="flex" justify="center">
          <template>
            <el-radio v-model="form.permission" label="0">普通用户</el-radio>
            <el-radio v-model="form.permission" label="1">管理员</el-radio>
          </template>
        </el-row>

        <el-row type="flex" justify="space-around">
          <el-form-item id="input_box_button">
            <el-button type="primary" @click="handleSubmit" :loading="logining">登陆</el-button>
            <el-button type="primary" @click="">重置</el-button>
            <el-button type="primary" @click="" :loading="logining">忘记密码</el-button>
          </el-form-item>
        </el-row>

      </div>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: "Middler",
    data() {
      return {
        logining: false,
        form: {
          numb: '',
          password: '',
          permission: '0'
        },
        rules: {
          numb: [{required: true, message: '请输入您的账号', trigger: 'blur'}],
          password: [{required: true, message: '输入您的密码', trigger: 'blur'}]
        }
      }
    },
    methods: {
      handleSubmit(event) {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.logining = true;
            this.$qs.stringify(this.form);
            // console.log(this.$qs.stringify(this.form));
            var url = this.HOME + '/ccwl/api/account/login';
            this.$axios.post(url,this.$qs.stringify(this.form)).then((response) => {
              this.logining = false;
              this.datalist = response.data;
              // console.log(this.datalist);
              sessionStorage.setItem('state',this.datalist.state);
              sessionStorage.setItem('state',this.datalist.state);
              if (this.datalist.state === "success") {
                alert("登陆成功");
                this.$router.push({ path:'/homepage'});
              }else {
                alert(this.datalist.msg);
                this.form.password = '';
                return;
              }
            })
          } else {
            return false;
          }
        })
      }
    }
  }
</script>

<style scoped>
  #box {
    width: 100%;
    height: 600px;
    position: relative;
    border: 1px solid #C0C0C0;
  }

  img {
    margin-left: 20px;
    margin-top: 50px;
    height: 500px;
  }

  #input_box {
    position: absolute;
    right: 50px;
    top: 50%;
    margin-top: -172.5px;
    height: 345px;
    width: 467px;
    border: 1px solid #C0C0C0;
  }

  #input_box_name {
    font-size: 25px;
    text-align: center;
    line-height: 63px;
    border-bottom: 1px solid #C0C0C0;
  }

  #input_box_content {
    margin-top: 50px;
  }

  .el-input {
    width: 250px;
  }

  #input_box_button {
    margin-top: 20px;
    margin-left: -50px;
  }
</style>
